﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Entities;
using Datalayer;

namespace Common
{
    public class cl_Insert
    {
        #region ChiTiet_Giaiphaphotro
        public static void ChiTiet_Giaiphaphotro_ins(string IDHongheo)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();
            List<GiaiPhap_KhacPhuc> gp;
            gp = iq.GPKP_GetAllGiaiPhap_KhacPhuc();
            for (int i = 0; i < gp.Count; i++)
            {
                ChiTiet_GiaiPhapHoTro ct = new ChiTiet_GiaiPhapHoTro();
                ct.GhiChu  ="";
                ct.IsDeleted = false;
                ct.Ma_GiaiPhap = gp[i].Ma_GiaiPhap;
                ct.Ma_HoNgheo = IDHongheo;
                ct.SoTien = 0;
                iq.Ctgpht_NewChiTiet_GiaiPhapHoTro(ct);
            }
        }
        public static void ChiTiet_Giaiphaphotro_edit(string IDHongheo,decimal[] money,string [] ghichu)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();
            List<GiaiPhap_KhacPhuc> gp;
            gp = iq.GPKP_GetAllGiaiPhap_KhacPhuc();
            for (int i = 0; i < gp.Count; i++)
            {
                ChiTiet_GiaiPhapHoTro ct = new ChiTiet_GiaiPhapHoTro();
                
                ct.GhiChu = ghichu[i];
                ct.IsDeleted = false;
                ct.Ma_GiaiPhap = gp[i].Ma_GiaiPhap;
                ct.Ma_HoNgheo = IDHongheo;
                ct.SoTien = money[i];
                iq.Ctgpht_EditChiTiet_GiaiPhapHoTro(ct);
            }
        }
        public static void ChiTiet_Giaiphaphotro_show(string IDHongheo,ref decimal[] money,ref string[] ghichu)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();
            List<GiaiPhap_KhacPhuc> gp;
            gp = iq.GPKP_GetAllGiaiPhap_KhacPhuc();
            for (int i = 0; i < gp.Count; i++)
            {
                ChiTiet_GiaiPhapHoTro ct = new ChiTiet_GiaiPhapHoTro();
                ct =iq.CTGPHT_GetChiTiet_GiaiPhapHoTroByIDGpandIDHongheo(gp[i].Ma_GiaiPhap,IDHongheo);
                money[i] = (decimal)ct.SoTien;
                ghichu[i] = ct.GhiChu;
            }
        }
        #endregion

        #region ChiTiet_ChiTieuHGD
        public static void ChiTiet_ChiTieuHGD_ins(string IDHongheo)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();
            List<LoaiChiTieu> gp;
            gp = iq.LCT_GetAllLoaiChiTieu();
            for (int i = 0; i < gp.Count; i++)
            {
                ChiTiet_ChiTieuHGD ct = new ChiTiet_ChiTieuHGD();
                
                ct.IsDeleted = false;
                ct.Ma_ChiTieu = gp[i].Ma_ChiTieu;
                ct.Ma_HoNgheo = IDHongheo;
                ct.Tien = 0;
                iq.Ctct_NewChiTiet_ChiTieuHGD(ct);
            }
        }
        public static void ChiTiet_ChiTieuHGD_edit(string IDHongheo, decimal[] money)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();
            List<LoaiChiTieu> gp;
            gp = iq.LCT_GetAllLoaiChiTieu();
            for (int i = 0; i < gp.Count; i++)
            {
                ChiTiet_ChiTieuHGD ct = new ChiTiet_ChiTieuHGD();

                
                ct.IsDeleted = false;
                ct.Ma_ChiTieu = gp[i].Ma_ChiTieu;
                ct.Ma_HoNgheo = IDHongheo;
                ct.Tien = money[i];
                iq.Ctct_EditChiTiet_ChiTieuHGD(ct);
            }
        }
        public static void ChiTiet_ChiTieuHGD_show(string IDHongheo, ref decimal[] money)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();
            List<LoaiChiTieu> gp;
            gp = iq.LCT_GetAllLoaiChiTieu();
            for (int i = 0; i < gp.Count; i++)
            {
                ChiTiet_ChiTieuHGD ct = new ChiTiet_ChiTieuHGD();
                ct = iq.CTCT_GetCTCTByIDandIDHN(gp[i].Ma_ChiTieu, IDHongheo);
                try
                {
                    money[i] = (decimal)ct.Tien;
                }
                catch
                { 
                }
            }
        }
        #endregion

        #region ChiTiet_ThuNhapHoGD
        public static void ChiTiet_ThuNhapHoGD_ins(string IDHongheo)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();
            List<LoaiHinhKinhTe> gp;
            gp = iq.LHKT_GetAllLoaiHinhKinhTe();
            for (int i = 0; i < gp.Count; i++)
            {
                ChiTiet_ThuNhapHoGD ct = new ChiTiet_ThuNhapHoGD();

                ct.IsDeleted = false;
                ct.Ma_LoaiHinhKinhTe = gp[i].Ma_LoaiHinhKinhTe;
                ct.Ma_HoNgheo = IDHongheo;
                ct.Thu = 0;
                ct.Chi = 0;
                iq.Cttnhgd_NewChiTiet_ThuNhapHoGD(ct);
            }
        }
        public static void ChiTiet_ThuNhapHoGD_edit(string IDHongheo, decimal[] moneyThu, decimal[] moneyChi)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();
            List<LoaiHinhKinhTe> gp;
            gp = iq.LHKT_GetAllLoaiHinhKinhTe();
            for (int i = 0; i < gp.Count; i++)
            {
                ChiTiet_ThuNhapHoGD ct = new ChiTiet_ThuNhapHoGD();


                ct.IsDeleted = false;
                ct.Ma_LoaiHinhKinhTe = gp[i].Ma_LoaiHinhKinhTe;
                ct.Ma_HoNgheo = IDHongheo;
                ct.Thu = moneyThu[i];
                ct.Chi = moneyChi[i];
                iq.Cttnhgd_EditChiTiet_ThuNhapHoGD(ct);
            }
        }
        public static void ChiTiet_ThuNhapHoGD_show(string IDHongheo, ref decimal[] moneyThu, ref decimal[] moneyChi)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();
            List<LoaiHinhKinhTe> gp;
            gp = iq.LHKT_GetAllLoaiHinhKinhTe();
            for (int i = 0; i < gp.Count; i++)
            {
                ChiTiet_ThuNhapHoGD ct = new ChiTiet_ThuNhapHoGD();
                ct = iq.CTTNHGD_GetChiTiet_ThuNhapHoGDByIDAndIDHN(gp[i].Ma_LoaiHinhKinhTe, IDHongheo);
                if (ct != null)
                {
                    moneyThu[i] = (decimal)ct.Thu;
                    moneyChi[i] = (decimal)ct.Chi;
                }
            }
        }
        #endregion

        #region ChiTiet_TaiSanHGD
        public static void ChiTiet_TaiSanHGD_ins(string IDHongheo)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();
            List<TaiSan> gp;
            gp = iq.TS_GetAllTaiSan();
            for (int i = 0; i < gp.Count; i++)
            {
                ChiTiet_TaiSanHGD ct = new ChiTiet_TaiSanHGD();

                ct.IsDeleted = false;
                ct.Ma_TaiSan = gp[i].Ma_TaiSan;
                ct.Ma_HoNgheo = IDHongheo;
                ct.Loai = "0";
                ct.DienTich_SoLuong = 0;
                ct.SoHuu = 0;
                ct.GiaTri = 0;
                iq.Ctts_NewChiTiet_TaiSanHGD(ct);
            }
        }
        public static void ChiTiet_TaiSanHGD_edit(string IDHongheo,string[]loai, int[] dientich, byte[] sohuu, decimal []giatri)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();
            List<TaiSan> gp;
            gp = iq.TS_GetAllTaiSan();
            for (int i = 0; i < gp.Count; i++)
            {
                ChiTiet_TaiSanHGD ct = new ChiTiet_TaiSanHGD();

                ct.IsDeleted = false;
                ct.Ma_TaiSan = gp[i].Ma_TaiSan;
                ct.Ma_HoNgheo = IDHongheo;
                ct.Loai = loai[i];
                ct.DienTich_SoLuong = dientich[i];
                ct.SoHuu = sohuu[i];
                ct.GiaTri = giatri[i];
                iq.Ctts_EditChiTiet_TaiSanHGD(ct);
            }
        }
        public static void ChiTiet_TaiSanHGD_show(string IDHongheo,ref string[] loai,ref int[] dientich,ref byte[] sohuu,ref decimal[] giatri)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();
            List<TaiSan> gp;
            gp = iq.TS_GetAllTaiSan();
            for (int i = 0; i < gp.Count; i++)
            {
                ChiTiet_TaiSanHGD ct = new ChiTiet_TaiSanHGD();
                ct = iq.CTTS_GetChiTiet_TaiSanHGDByIDAndIdHN(gp[i].Ma_TaiSan, IDHongheo);
                loai[i] = ct.Loai;
                dientich[i] = (int)ct.DienTich_SoLuong;
                sohuu[i] = (byte)ct.SoHuu;
                giatri[i] = (decimal)ct.GiaTri;
            }
        }
        #endregion
    }
}
